#include "fedom.h"
#include "fedom_private.h"

// FeDOMNode
FeDOMNode::FeDOMNode()
{
	FeDOMNodePrivate *ref = new FeDOMNodePrivate;
	d = ref;
	ref->data = 0;
}

FeDOMNode::FeDOMNode(const FeDOMNode &node)
{
	FeDOMNodePrivate *ref = new FeDOMNodePrivate;
	d = ref;
	FeDOMNodePrivate *node_ref = (FeDOMNodePrivate *)(node.d);
	if(node_ref->data)
	{
		node_ref->data->ref_count++;
		ref->data = node_ref->data;
	}
	else
	{
		ref->data = 0;
	}
}

FeDOMNode::~FeDOMNode() {
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	if(ref->data)
	{
		ref->data->ref_count--;
		if(!ref->data->ref_count)
		{
			delete ref->data;
		}
		ref->data = 0;
	}
	delete d;
}

FeDOMNode &FeDOMNode::operator=(const FeDOMNode &node) {
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	if(ref->data)
	{
		ref->data->ref_count--;
		if(!ref->data->ref_count)
		{
			delete ref->data;
		}
		ref->data = 0;
	}

	FeDOMNodePrivate *node_ref = (FeDOMNodePrivate *)(node.d);
	if(node_ref->data)
	{
		node_ref->data->ref_count++;
		ref->data = node_ref->data;
	}

	return *this;
}

bool FeDOMNode::isNull() const
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	return !ref->data;
}

FeDOMNode::NodeType FeDOMNode::nodeType() const
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	if(ref->data)
	{
		return ref->data->node_type;
	}
	else
	{
		return FeDOMNode::Node;
	}
}

FeDOMDocument FeDOMNode::document() const
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	FeDOMNodeData *data = (FeDOMNodeData *)ref->data;
	Q_ASSERT(data);
	return FeDOMDocument(data);
}

bool FeDOMNode::isInSameDocument(const FeDOMNode &node) const
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	FeDOMNodePrivate *node_ref = (FeDOMNodePrivate *)(node.d);
	return ref->data && node_ref->data && ref->data->doc == node_ref->data->doc;
}

bool operator==(const FeDOMNode &node1, const FeDOMNode &node2)
{
	FeDOMNodePrivate *ref1 = (FeDOMNodePrivate *)(node1.d);
	FeDOMNodePrivate *ref2 = (FeDOMNodePrivate *)(node2.d);
	return ref1->data == ref2->data;
}

// FeDOMProperty
FeDOMProperty::FeDOMProperty()
: FeDOMNode()
{
}

FeDOMProperty::FeDOMProperty(const FeDOMProperty &prop)
: FeDOMNode(prop)
{

}

FeDOMProperty &FeDOMProperty::operator=(const FeDOMProperty &prop) 
{
	FeDOMNode::operator=(prop);
	return *this;
}

QString FeDOMProperty::name() const
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMPropertyData *data = (FeDOMPropertyData *)(ref->data);
	return data->name;
}

void FeDOMProperty::setName(const QString &v)
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMPropertyData *data = (FeDOMPropertyData *)(ref->data);
	data->name = v;
}

QVariant FeDOMProperty::value() const
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMPropertyData *data = (FeDOMPropertyData *)(ref->data);
	return data->value;
}

void FeDOMProperty::setValue(const QVariant &v)
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMPropertyData *data = (FeDOMPropertyData *)(ref->data);
	data->value = v;
}

// FeDOMSignalBind
FeDOMSignalBind::FeDOMSignalBind()
: FeDOMNode()
{
}

FeDOMSignalBind::FeDOMSignalBind(const FeDOMSignalBind &bind)
: FeDOMNode(bind)
{
}

FeDOMSignalBind &FeDOMSignalBind::operator=(const FeDOMSignalBind &bind)
{
	FeDOMNode::operator=(bind);
	return *this;
}

FeActualDataId FeDOMSignalBind::signalId() const
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMSignalBindData *data = (FeDOMSignalBindData *)(ref->data);
	return data->signal;
}

void FeDOMSignalBind::setSignalId(const FeActualDataId &v)
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMSignalBindData *data = (FeDOMSignalBindData *)(ref->data);
	data->signal = v;
}

QString FeDOMSignalBind::widgetName() const
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMSignalBindData *data = (FeDOMSignalBindData *)(ref->data);
	return data->widget;
}

void FeDOMSignalBind::setWidgetName(const QString &v)
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMSignalBindData *data = (FeDOMSignalBindData *)(ref->data);
	data->widget = v;
}

QString FeDOMSignalBind::propertyName() const
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMSignalBindData *data = (FeDOMSignalBindData *)(ref->data);
	return data->property;

}

void FeDOMSignalBind::setPropertyName(const QString &v)
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMSignalBindData *data = (FeDOMSignalBindData *)(ref->data);
	data->property = v;
}

// FeDOMSignalBinding
FeDOMSignalBinding::FeDOMSignalBinding()
: FeDOMNode()
{
}

FeDOMSignalBinding::FeDOMSignalBinding(const FeDOMSignalBinding &bind)
: FeDOMNode(bind)
{
}

FeDOMSignalBinding &FeDOMSignalBinding::operator=(const FeDOMSignalBinding &bind)
{
	FeDOMNode::operator =(bind);
	return *this;
}

QList<FeDOMSignalBind> FeDOMSignalBinding::bindings() const
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMSignalBindingData *data = (FeDOMSignalBindingData *)(ref->data);
	return data->bindings;
}

void FeDOMSignalBinding::add(const FeDOMSignalBind &v)
{
	Q_ASSERT(isInSameDocument(v));

	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMSignalBindingData *data = (FeDOMSignalBindingData *)(ref->data);
	data->bindings.append(v);
}

// FeDOMLayoutItem
FeDOMLayoutItem::FeDOMLayoutItem()
: FeDOMNode()
{
}

FeDOMLayoutItem::FeDOMLayoutItem(const FeDOMLayoutItem &item)
: FeDOMNode(item)
{
}

FeDOMLayoutItem &FeDOMLayoutItem::operator=(const FeDOMLayoutItem &item)
{
	FeDOMNode::operator =(item);
	return *this;
}

// FeDOMWidget
FeDOMWidget::FeDOMWidget()
: FeDOMLayoutItem()
{
}

FeDOMWidget::FeDOMWidget(const FeDOMWidget &widget)
: FeDOMLayoutItem(widget)
{
}

FeDOMWidget &FeDOMWidget::operator=(const FeDOMWidget &widget)
{
	FeDOMLayoutItem::operator =(widget);
	return *this;
}

QString FeDOMWidget::name() const
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMWidgetData *data = (FeDOMWidgetData *)(ref->data);
	return data->name;
}

void FeDOMWidget::setName(const QString &v)
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMWidgetData *data = (FeDOMWidgetData *)(ref->data);
	data->name = v;
}

QString FeDOMWidget::type() const
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMWidgetData *data = (FeDOMWidgetData *)(ref->data);
	return data->type;
}

void FeDOMWidget::setType(const QString &v)
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMWidgetData *data = (FeDOMWidgetData *)(ref->data);
	data->type = v;
}

QList<FeDOMProperty> FeDOMWidget::properties() const
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMWidgetData *data = (FeDOMWidgetData *)(ref->data);
	return data->properties.values();
}

FeDOMProperty FeDOMWidget::getProperty(const QString &name) const
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMWidgetData *data = (FeDOMWidgetData *)(ref->data);
	QHash<QString, FeDOMProperty>::iterator it = data->properties.find(name);
	if(it != data->properties.end())
	{
		return it.value();
	}
	return FeDOMProperty();
}

void FeDOMWidget::addProperty(const FeDOMProperty &prop)
{
	Q_ASSERT(isInSameDocument(prop));
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMWidgetData *data = (FeDOMWidgetData *)(ref->data);
	data->properties.insert(prop.name(), prop);
}

void FeDOMWidget::removeProperty(const FeDOMProperty &prop)
{
	Q_ASSERT(isInSameDocument(prop));
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMWidgetData *data = (FeDOMWidgetData *)(ref->data);
	data->properties.remove(prop.name());
}

// FeDOMLayout
FeDOMLayout::FeDOMLayout()
: FeDOMLayoutItem()
{
}

FeDOMLayout::FeDOMLayout(const FeDOMLayout &layout)
: FeDOMLayoutItem(layout)
{
}

FeDOMLayout &FeDOMLayout::operator=(const FeDOMLayout &layout)
{
	FeDOMLayoutItem::operator =(layout);
	return *this;
}

QList<FeDOMLayoutItem> FeDOMLayout::items() const
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMLayoutData *data = (FeDOMLayoutData *)(ref->data);
	return data->items;
}

void FeDOMLayout::addItem(const FeDOMLayoutItem &item)
{
	Q_ASSERT(isInSameDocument(item));

	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMLayoutData *data = (FeDOMLayoutData *)(ref->data);
	data->items.append(item);
}

void FeDOMLayout::removeItem(const FeDOMHBoxLayout &item)
{
	Q_ASSERT(isInSameDocument(item));

	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMLayoutData *data = (FeDOMLayoutData *)(ref->data);
	data->items.removeAll(item);
}

// FeDOMVBoxLayout
FeDOMVBoxLayout::FeDOMVBoxLayout()
: FeDOMLayout()
{
}

FeDOMVBoxLayout::FeDOMVBoxLayout(const FeDOMVBoxLayout &layout)
: FeDOMLayout(layout)
{
}

FeDOMVBoxLayout &FeDOMVBoxLayout::operator=(const FeDOMVBoxLayout &layout)
{
	FeDOMLayout::operator =(layout);
	return *this;
}

int FeDOMVBoxLayout::margin() const
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMVBoxLayoutData *data = (FeDOMVBoxLayoutData *)(ref->data);
	return data->margin;
}

void FeDOMVBoxLayout::setMargin(int v)
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMVBoxLayoutData *data = (FeDOMVBoxLayoutData *)(ref->data);
	data->margin = v;
}

int FeDOMVBoxLayout::spacing() const
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMVBoxLayoutData *data = (FeDOMVBoxLayoutData *)(ref->data);
	return data->spacing;
}

void FeDOMVBoxLayout::setSpacing(int v)
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMVBoxLayoutData *data = (FeDOMVBoxLayoutData *)(ref->data);
	data->spacing = v;
}

// FeDOMHBoxLayout
FeDOMHBoxLayout::FeDOMHBoxLayout()
: FeDOMLayout()
{
}

FeDOMHBoxLayout::FeDOMHBoxLayout(const FeDOMHBoxLayout &layout)
: FeDOMLayout(layout)
{
}

FeDOMHBoxLayout &FeDOMHBoxLayout::operator=(const FeDOMHBoxLayout &layout)
{
	FeDOMLayout::operator =(layout);
	return *this;
}

int FeDOMHBoxLayout::margin() const
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMHBoxLayoutData *data = (FeDOMHBoxLayoutData *)(ref->data);
	return data->margin;
}

void FeDOMHBoxLayout::setMargin(int v)
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMHBoxLayoutData *data = (FeDOMHBoxLayoutData *)(ref->data);
	data->margin = v;
}

int FeDOMHBoxLayout::spacing() const
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMHBoxLayoutData *data = (FeDOMHBoxLayoutData *)(ref->data);
	return data->spacing;
}

void FeDOMHBoxLayout::setSpacing(int v)
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMHBoxLayoutData *data = (FeDOMHBoxLayoutData *)(ref->data);
	data->spacing = v;
}

// FeDOMScaleLayout
FeDOMScaleLayout::FeDOMScaleLayout()
: FeDOMLayout()
{
}

FeDOMScaleLayout::FeDOMScaleLayout(const FeDOMScaleLayout &layout)
: FeDOMLayout(layout)
{
}

FeDOMScaleLayout &FeDOMScaleLayout::operator=(const FeDOMScaleLayout &layout)
{
	FeDOMLayout::operator =(layout);
	return *this;
}

QSize FeDOMScaleLayout::size() const
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMScaleLayoutData *data = (FeDOMScaleLayoutData *)(ref->data);
	return data->size;
}

void FeDOMScaleLayout::setSize(const QSize &v)
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMScaleLayoutData *data = (FeDOMScaleLayoutData *)(ref->data);
	data->size = v;
}

// FeDOMScreen
FeDOMScreen::FeDOMScreen()
: FeDOMNode()
{
}

FeDOMScreen::FeDOMScreen(const FeDOMScreen &screen)
: FeDOMNode(screen)
{
}

FeDOMScreen &FeDOMScreen::operator=(const FeDOMScreen &screen)
{
	FeDOMNode::operator =(screen);
	return *this;
}

QList<FeDOMProperty> FeDOMScreen::properties() const
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMScreenData *data = (FeDOMScreenData *)(ref->data);
	return data->properties.values();
}

FeDOMProperty FeDOMScreen::getProperty(const QString &name) const
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMScreenData *data = (FeDOMScreenData *)(ref->data);
	QHash<QString, FeDOMProperty>::iterator it = data->properties.find(name);
	if(it != data->properties.end())
	{
		return it.value();
	}
	return FeDOMProperty();
}

void FeDOMScreen::addProperty(const FeDOMProperty &prop)
{
	Q_ASSERT(isInSameDocument(prop));

	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMScreenData *data = (FeDOMScreenData *)(ref->data);
	data->properties.insert(prop.name(), prop);
}

void FeDOMScreen::removeProperty(const FeDOMProperty &prop)
{
	Q_ASSERT(isInSameDocument(prop));

	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMScreenData *data = (FeDOMScreenData *)(ref->data);
	data->properties.remove(prop.name());
}

FeDOMLayout FeDOMScreen::layout() const
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMScreenData *data = (FeDOMScreenData *)(ref->data);
	return data->layout;
}

void FeDOMScreen::setLayout(const FeDOMLayout &v)
{
	Q_ASSERT(isInSameDocument(v));

	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMScreenData *data = (FeDOMScreenData *)(ref->data);
	data->layout = v;
}

FeDOMSignalBinding FeDOMScreen::signalBinding() const
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMScreenData *data = (FeDOMScreenData *)(ref->data);
	return data->binding;
}

void FeDOMScreen::setSignalBinding(const FeDOMSignalBinding &v)
{
	Q_ASSERT(isInSameDocument(v));

	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMScreenData *data = (FeDOMScreenData *)(ref->data);
	data->binding = v;
}

// FeDOMDocument
FeDOMDocument::FeDOMDocument()
: FeDOMNode()
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	FeDOMDocumentData *data = new FeDOMDocumentData;
	data->ref_count = 1;
	data->doc = data;
	data->node_type = FeDOMNode::Document;
	data->screen = FeDOMScreen();
	ref->data = data;
}

FeDOMDocument::FeDOMDocument(void *data_ptr)
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	FeDOMDocumentData *data = (FeDOMDocumentData *)data_ptr;
	data->ref_count++;
	ref->data = data;
}

FeDOMDocument::FeDOMDocument(const FeDOMDocument &doc)
: FeDOMNode(doc)
{
}

FeDOMDocument &FeDOMDocument::operator=(const FeDOMDocument &doc)
{
	FeDOMNode::operator =(doc);
	return *this;
}

FeDOMProperty FeDOMDocument::createProperty(const QString &name, const QVariant &value)
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	FeDOMDocumentData *data = (FeDOMDocumentData *)ref->data;

	FeDOMProperty v = FeDOMProperty();
	FeDOMNodePrivate *&v_ref = (FeDOMNodePrivate *&)(v.d);
	FeDOMPropertyData *v_data = new FeDOMPropertyData;
	v_data->ref_count = 1;
	v_data->doc = data;
	v_data->node_type = FeDOMNode::Property;
	v_data->name = name;
	v_data->value = value;
	v_ref->data = v_data;
		 
	return v;
}

FeDOMSignalBind FeDOMDocument::createSignalBind(const FeActualDataId &signal, const QString &widget, const QString &property)
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	FeDOMDocumentData *data = (FeDOMDocumentData *)ref->data;

	FeDOMSignalBind v = FeDOMSignalBind();
	FeDOMNodePrivate *&v_ref = (FeDOMNodePrivate *&)(v.d);
	FeDOMSignalBindData *v_data = new FeDOMSignalBindData;
	v_data->ref_count = 1;
	v_data->doc = data;
	v_data->node_type = FeDOMNode::SignalBind;
	v_data->signal = signal;
	v_data->widget = widget;
	v_data->property = property;
	v_ref->data = v_data;
		 
	return v;
}

FeDOMSignalBinding FeDOMDocument::createSignalBinding()
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	FeDOMDocumentData *data = (FeDOMDocumentData *)ref->data;

	FeDOMSignalBinding v = FeDOMSignalBinding();
	FeDOMNodePrivate *&v_ref = (FeDOMNodePrivate *&)(v.d);
	FeDOMSignalBindingData *v_data = new FeDOMSignalBindingData;
	v_data->ref_count = 1;
	v_data->doc = data;
	v_data->node_type = FeDOMNode::SignalBinding;
	v_ref->data = v_data;
		 
	return v;
}

FeDOMWidget FeDOMDocument::createWidget(const QString &name, const QString &type)
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	FeDOMDocumentData *data = (FeDOMDocumentData *)ref->data;

	FeDOMWidget v = FeDOMWidget();
	FeDOMNodePrivate *&v_ref = (FeDOMNodePrivate *&)(v.d);
	FeDOMWidgetData *v_data = new FeDOMWidgetData;
	v_data->ref_count = 1;
	v_data->doc = data;
	v_data->node_type = FeDOMNode::Widget;
	v_data->name = name;
	v_data->type = type;
	v_ref->data = v_data;
		 
	return v;
}

FeDOMHBoxLayout FeDOMDocument::createHBoxLayout(int margin, int spacing)
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	FeDOMDocumentData *data = (FeDOMDocumentData *)ref->data;

	FeDOMHBoxLayout v = FeDOMHBoxLayout();
	FeDOMNodePrivate *&v_ref = (FeDOMNodePrivate *&)(v.d);
	FeDOMHBoxLayoutData *v_data = new FeDOMHBoxLayoutData;
	v_data->ref_count = 1;
	v_data->doc = data;
	v_data->node_type = FeDOMNode::HBoxLayout;
	v_data->margin = margin;
	v_data->spacing = spacing;
	v_ref->data = v_data;
		 
	return v;
}

FeDOMVBoxLayout FeDOMDocument::createVBoxLayout(int margin, int spacing)
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	FeDOMDocumentData *data = (FeDOMDocumentData *)ref->data;

	FeDOMVBoxLayout v = FeDOMVBoxLayout();
	FeDOMNodePrivate *&v_ref = (FeDOMNodePrivate *&)(v.d);
	FeDOMVBoxLayoutData *v_data = new FeDOMVBoxLayoutData;
	v_data->ref_count = 1;
	v_data->doc = data;
	v_data->node_type = FeDOMNode::VBoxLayout;
	v_data->margin = margin;
	v_data->spacing = spacing;
	v_ref->data = v_data;
		 
	return v;
}

FeDOMScaleLayout FeDOMDocument::createScaleLayout(const QSize &size)
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	FeDOMDocumentData *data = (FeDOMDocumentData *)ref->data;

	FeDOMScaleLayout v = FeDOMScaleLayout();
	FeDOMNodePrivate *&v_ref = (FeDOMNodePrivate *&)(v.d);
	FeDOMScaleLayoutData *v_data = new FeDOMScaleLayoutData;
	v_data->ref_count = 1;
	v_data->doc = data;
	v_data->node_type = FeDOMNode::ScaleLayout;
	v_data->size = size;
	v_ref->data = v_data;
		 
	return v;
}

FeDOMScreen FeDOMDocument::createScreen()
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	FeDOMDocumentData *data = (FeDOMDocumentData *)ref->data;

	FeDOMScreen v = FeDOMScreen();
	FeDOMNodePrivate *&v_ref = (FeDOMNodePrivate *&)(v.d);
	FeDOMScreenData *v_data = new FeDOMScreenData;
	v_data->ref_count = 1;
	v_data->doc = data;
	v_data->node_type = FeDOMNode::Screen;
	v_ref->data = v_data;
		 
	return v;
}

FeDOMScreen FeDOMDocument::screen() const
{
	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMDocumentData *data = (FeDOMDocumentData *)(ref->data);
	return data->screen;
}

void FeDOMDocument::setScreen(const FeDOMScreen &v)
{
	Q_ASSERT(isInSameDocument(v));

	FeDOMNodePrivate *ref = (FeDOMNodePrivate *)d;
	Q_ASSERT(ref->data);

	FeDOMDocumentData *data = (FeDOMDocumentData *)(ref->data);
	data->screen = v;
}